package com.fc.authentication.modules.member.service;

import com.fc.authentication.common.exception.RRException;
import com.fc.authentication.modules.member.domain.Member;
import com.fc.authentication.modules.member.dto.MemberCreateRequest;
import com.fc.authentication.modules.member.repository.MemberRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * Created by Sunny on 2018/6/28.
 */
@Service
public class MemberService {

    @Autowired
    private MemberRepository memberRepository;


    public void createMember(MemberCreateRequest memberCreateRequest)
    {
        try {
            Member member = Member.createMember();
            member.setName(memberCreateRequest.getName());
            member.setAge(memberCreateRequest.getAge());
            member.setEmail(memberCreateRequest.getEmail());
            member.setMobile(memberCreateRequest.getMobile());
            memberRepository.save(member);
        }
        catch (Exception e)
        {
            new RRException("保存会员信息失败");
        }
    }

    public Page<Member> findMemberList(Pageable pageable)
    {
        Page<Member> memberPage = memberRepository.findAll(pageable);

        return  memberPage;
    }
}
